<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@include file="/includes.jsp"%>

<div class="layout">
    <table class="layout">
        <tr>
            <th class="layout">Date:</th>
            <td class="layout">
                <html:form action="personTime.do?method=showTime" method="post">
                    <html:hidden name="personTimeActionForm" property="nodeId"/>
                    <html:select name="personTimeActionForm" property="year" size="1">
                        <html:options collection="years" property="integer" labelProperty="string"/>
                    </html:select>-<html:select name="personTimeActionForm" property="month" size="1">
                        <html:options collection="months" property="integer" labelProperty="string"/>
                    </html:select>-<html:select name="personTimeActionForm" property="day" size="1">
                        <html:options collection="days" property="integer" labelProperty="string"/>
                    </html:select>
                    <html:submit property="btnSubmit" value="<"/>
                    <html:submit property="btnSubmit" value="Go"/>
                    <html:submit property="btnSubmit" value=">"/>
                </html:form>
            </td>
        </tr>
        <tr>
            <th class="layout">Duration:</th>
            <beans:define id="duration" name="personDuration"/>
            <jsp:useBean id="beanDurationHours" class="java.util.Date"/>
            <jsp:useBean id="beanDurationMins" class="java.util.Date"/>
            <jsp:setProperty name="beanDurationHours" property="time" value="<%=((Long)duration).longValue()/3600000L%>"/>
            <jsp:setProperty name="beanDurationMins" property="time" value="<%=(((Long)duration).longValue()/60000L)%60L%>"/>
            <td class="layout"><beans:write name="beanDurationHours" property="time" format="##"/>h:<beans:write name="beanDurationMins" property="time" format="00"/>m</td>
        </tr>
    </table>
    <table class="styled" cellspacing="0">
        <tr>
            <th class="styled">Task</th>
            <th class="styled">Description</th>
            <th class="styled">State</th>
            <th class="styled">Start</th>
            <th class="styled">Stop</th>
            <th class="styled">Duration</th>
            <th class="styled">Remaining</th>
            <th class="styled">Graphical</th>
            <th class="styled">Edit?</th>
            <th class="styled">Delete?</th>
        </tr>
        <logic:iterate name="personTimeValues" id="time">
            <tr>
                <td class="styled">
                    <html:link action="showNode.do" paramId="nodeId" paramName="time" paramProperty="taskId">
                        <beans:write name="time" property="taskName"/>
                    </html:link>
                </td>
                <td class="styled"><velocityme:markup><beans:write name="time" property="description"/></velocityme:markup></td>
                <td class="styled"><beans:write name="time" property="stateName"/></td>
                <td class="styled"><beans:write name="time" property="start" format="yyyy-MM-dd HH:mm:ss"/></td>
                <td class="styled"><beans:write name="time" property="stop" format="HH:mm:ss"/></td>
                <jsp:setProperty name="beanDurationHours" property="time" value="<%=((TimeDTO)time).getDuration()/3600000L%>"/>
                <jsp:setProperty name="beanDurationMins" property="time" value="<%=(((TimeDTO)time).getDuration()/60000L)%60L%>"/>
                <td class="styled"><beans:write name="beanDurationHours" property="time" format="##"/>h:<beans:write name="beanDurationMins" property="time" format="00"/>m</td>
                <beans:define id="remaining" value="<%=TaskValueToString.expectedDurationToString(((TimeDTO)time).getRemainingDuration_min())%>"/>
                <td class="styled"><beans:write name="remaining"/></td>
                <td class="styled">
                    <div style="float: left; width: <%=(((TimeDTO)time).getStart().getTime()%(3600000L*24L))*100L/(3600000L*24L)%>%">&nbsp;</div>
                    <div class="histogram" style="float: left; width: <%=((TimeDTO)time).getDuration()*100L/(3600000L*24L)%>%">&nbsp;</div>
                </td>
                <html:form action="timeEdit.do?method=showTimeEdit" method="post">
                    <html:hidden name="time" property="timeId"/>
                    <td class="styled" style="text-align: center;">
                        <logic:equal name="time" property="isEditable" value="true">
                            <html:submit property="btnEdit" value="Edit"/>
                        </logic:equal>
                        <logic:notEqual name="time" property="isEditable" value="true">
                            No permission
                        </logic:notEqual>
                    </td>
                </html:form>
                <html:form action="timeEdit.do?method=timeDeleteCheck" method="post">
                    <html:hidden name="time" property="timeId"/>
                    <td class="styled" style="text-align: center;">
                        <logic:equal name="time" property="isDeletable" value="true">
                            <html:submit property="btnDelete" value="Delete"/>
                        </logic:equal>
                        <logic:notEqual name="time" property="isDeletable" value="true">
                            No permission
                        </logic:notEqual>
                    </td>
                </html:form>
            </tr>
        </logic:iterate>
    </table>
    
    <logic:notEmpty name="taskPairs">
        <html:errors/>
        <html:form action="time.do?method=timeEdit" method="post">
            <table class="layout">
                <tr>
                    <th class="layout">Description:</th>
                    <td class="layout"><html:textarea name="timeValue" property="description" cols="60" rows="5"/></td>
                </tr>
                <tr>
                    <th class="layout">Task:</th>
                    <td class="layout">
                        <html:select name="timeActionForm" property="taskId" onchange="doubleCombo(this.options.selectedIndex, document.timeValueActionForm.stateId)">
                            <html:options collection="taskPairs" property="integer" labelProperty="string"/>
                        </html:select>
                    </td>
                </tr>
                <tr>
                    <th class="layout">% Complete:</th>
                    <td class="layout">
                        <html:select name="timeActionForm" property="percentageComplete">
                            <html:options collection="completePairs" property="integer" labelProperty="string"/>
                        </html:select>
                    </td>
                </tr>
                <tr>
                    <th class="layout">Remaining Duration:</th>
                    <td class="layout">
                        <html:select name="timeActionForm" property="durationDays">
                            <html:options collection="durationDays" property="integer" labelProperty="string"/>
                        </html:select>day:<html:select name="timeActionForm" property="durationHours">
                            <html:options collection="durationHours" property="integer" labelProperty="string"/>
                        </html:select>hr:<html:select name="timeActionForm" property="durationMins">
                            <html:options collection="minutes" property="integer" labelProperty="string"/>
                        </html:select>min
                    </td>
                </tr>
                <tr>
                    <th class="layout">State:</th>
                    <td class="layout">
                        <html:select name="timeActionForm" property="stateId">
                            <html:options collection="statePairs" property="integer" labelProperty="string"/>
                        </html:select>
                    </td>
                </tr>
                <tr>
                    <th class="layout">Date:</th>
                    <td class="layout">
                        <html:select name="timeActionForm" property="year" size="1">
                            <html:options collection="years" property="integer" labelProperty="string"/>
                        </html:select>-<html:select name="timeActionForm" property="month" size="1">
                            <html:options collection="months" property="integer" labelProperty="string"/>
                        </html:select>-<html:select name="timeActionForm" property="day" size="1">
                            <html:options collection="days" property="integer" labelProperty="string"/>
                        </html:select>
                       Start:<html:select name="timeActionForm" property="startHour" size="1">
                            <html:options collection="hours" property="integer" labelProperty="string"/>
                        </html:select>h:<html:select name="timeActionForm" property="startMinute" size="1">
                            <html:options collection="minutes" property="integer" labelProperty="string"/>
                        </html:select>
                        Stop:<html:select name="timeActionForm" property="stopHour" size="1">
                            <html:options collection="hours" property="integer" labelProperty="string"/>
                        </html:select>h:<html:select name="timeActionForm" property="stopMinute" size="1">
                            <html:options collection="minutes" property="integer" labelProperty="string"/>
                        </html:select>
                    </td>
                </tr>
            </table>
            <div class="buttons">
                <html:submit property="btnSubmit" value="OK"/>
            </div>
        </html:form>
    </logic:notEmpty>
</div>

<script type="text/javascript">

var groups=document.timeValueActionForm.taskId.options.length
var complete=new Array(groups)
var durDays=new Array(groups)
var durHours=new Array(groups)
var durMins=new Array(groups)
var group=new Array(groups)
for (i=0; i<groups; i++)
    group[i]=new Array()

<logic:iterate name="personTimeActionForm2" property="percentageCompletes" id="pc" indexId="i">
    complete[<beans:write name="i"/>]=<beans:write name="pc"/>
</logic:iterate>
    
<logic:iterate name="personTimeActionForm2" property="durationDays" id="dd" indexId="i">
    durDays[<beans:write name="i"/>]=<beans:write name="dd"/>
</logic:iterate>
    
<logic:iterate name="personTimeActionForm2" property="durationHours" id="dh" indexId="i">
    durHours[<beans:write name="i"/>]=<beans:write name="dh"/>
</logic:iterate>
    
<logic:iterate name="personTimeActionForm2" property="durationMins" id="dm" indexId="i">
    durMins[<beans:write name="i"/>]=<beans:write name="dm"/>
</logic:iterate>
    
<logic:iterate name="personTimeActionForm2" property="statePairs" id="sp" indexId="i">
    <logic:iterate name="sp" id="value" indexId="j">
        group[<beans:write name="i"/>][<beans:write name="j"/>]=new Option("<beans:write name="value" property="string"/>", "<beans:write name="value" property="integer"/>")
    </logic:iterate>
</logic:iterate>

function doubleCombo(x, stage2) {
    document.timeValueActionForm.percentageComplete.options[complete[x]/5].selected=true
    document.timeValueActionForm.durationDays.options[durDays[x]].selected=true
    document.timeValueActionForm.durationHours.options[durHours[x]].selected=true
    document.timeValueActionForm.durationMins.options[durMins[x]/5].selected=true
    for (m=stage2.options.length-1;m>0;m--)
        stage2.options[m]=null
    for (i=0;i<group[x].length;i++)
        stage2.options[i]=new Option(group[x][i].text,group[x][i].value)
    stage2.options[0].selected=true
}

</script>
